<template>
  <view class="container">
    <view class="form">
      <text class="title">登录</text>
      <input class="input" placeholder="请输入用户名" v-model="username" />
      <input class="input" placeholder="请输入密码" v-model="password" type="password" />
      <button class="btn" type="primary" @click="handleLogin">登录</button>
      <view class="link">
        <text>没有账号？</text>
        <navigator url="/pages/register/register" open-type="navigate">去注册</navigator>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: ''
    }
  },
  onLoad() {
  	console.log("component--->onLode")
  },
  methods: {
    handleLogin() {
      if (this.username && this.password) {
		  uni.switchTab({
		  	url:'/pages/tabBar/component/component'
		  });
        uni.showToast({
			  title: '登录成功',
			  icon: 'success'
        
        })
		uni.setStorage({
			key:'username',
			data:this.username,
			success:function(){
				console.log("setStorage");
				console.log("setStorage---->data:"+this.username)
			}
		})
		uni.switchTab({
			url:'/pages/tabBar/component/component'
		})
      }else{
      uni.showToast({
       title: '请输入完整信息',
       icon: 'none'
      });
    }
  }
  }
};
</script>

<style >
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f5f5f5;
}
.form {
  width: 80%;
  background-color: #fff;
  padding: 30rpx;
  border-radius: 10rpx;
  box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.1);
}
.title {
  display: block;
  font-size: 40rpx;
  font-weight: bold;
  margin-bottom: 30rpx;
  text-align: center;
}
.input {
  width: 100%;
  height: 80rpx;
  border: 1rpx solid #ddd;
  border-radius: 6rpx;
  margin-bottom: 20rpx;
  padding: 0 20rpx;
  box-sizing: border-box;
}
.btn {
  margin-top: 30rpx;
}
.link {
  display: flex;
  justify-content: center;
  margin-top: 20rpx;
  font-size: 28rpx;
  color: #666;
}
.link navigator {
  color: #007aff;
  margin-left: 10rpx;
}
</style>